/**
 * Created by Administrator on 2017/9/20.
 */
angular.module('service.news', [
        "ngResource",
    ])
    .service('NewsService', NewsService);
NewsService.$inject = ['$resource'];
function NewsService($resource) {

    // 通过店铺id获取消息
    this.getNewsByShopId = function (shopid, handleid, starttime, endtime, sucF, errF) {
        var resource = $resource(deviceurl + "shotabcal/bytimshophanid/:shopid/:handleid");
        return resource.query({shopid: shopid, handleid: handleid, starttime: starttime, endtime: endtime}, sucF, errF);
    };

    // 修改消息状态
    this.updateNews = function (news, success, error) {
        var resource = $resource(deviceurl + "shotabcal/bytabshoid", {}, {
            save: {
                method: "POST",
                isArray: true,
            }
        });
        return resource.save(news, success, error);
    };

    // 通过shopid获取桌台信息
    this.getTablesByShopId = function (shopid, tablestatus) {
        var resource = $resource(merchanturl + "shoptable/:shopid/:tablestatus");
        return resource.query({shopid: shopid, tablestatus: tablestatus});
    };

    //根据店铺id查询 
    this.getShopinfoByShopid = function (shopid,success,error) {
        var resource = $resource(merchanturl + "shopinfo/shopid/:shopid");
        return resource.get({shopid: shopid},success,error);
    };

    // 通过处理情况获取消息�
    //this.getnewsbyhandleid = function (shopid,handleid,startime,endtime,success,error) {
    //    var resource = $resource(deviceurl + "/shotabcal/bytimshophanid/:shopid/:handleid");
    //    return resource.query({shopid:shopid,handleid:handleid,startime:startime,endtime:endtime},success,error);
    //}

    // 通过tableid获取桌台名
    this.getTableByTableId = function (tableid, success, error) {
        var resource = $resource(merchanturl + "shoptable/:tableid");
        return resource.get({tableid: tableid}, success, error);
    };

    // 退出去时候清除定时器和语音
    var contrlStatus = {};

    this.setStatus = function (name, audioSrc) {
        contrlStatus[name] = audioSrc;
    };

    this.getStatus = function (name) {
        return contrlStatus[name];
    };

    this.getNewsByPage = function (shopid, handleid, page, sucD, errD) {
        var resource = $resource(deviceurl + "shotabcal/bypage/:shopid");
        return resource.query({
            shopid: shopid,
            handleid: handleid,
            pages: page.pages,
            pagesize: page.pagesize
        }, sucD, errD);
    };

    // 获取桌台历史消息
    this.getNewsByTable = function (shopid, tableid, starttime, endtime, sucD, errD) {
        var resource = $resource(deviceurl + "shotabcal/bytimesids/:tableid/:shopid");
        return resource.query({shopid: shopid, tableid: tableid, starttime: starttime, endtime: endtime}, sucD, errD);
    };

    // 推送消息到桌台设备
    this.sendNews = function (shotabcal, success, error) {
        var resource = $resource(deviceurl + "shotabcal/bytabshoid");
        return resource.save(shotabcal, success, error);
    }
}